local sk__yinyuan = fk.CreateSkill {

  name = "sk__yinyuan",

  tags = {  },

}



sk__yinyuan:addEffect(fk.EventPhaseStart, {
  name = "sk__yinyuan",
  anim_type = "support",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(sk__yinyuan.name) and player.phase == Player.Finish
  end,
  on_cost = function (self, event, target, player, data)
    local alivePlayerIds = table.map(player.room.alive_players, Util.IdMapper)
    local to = player.room:askForChoosePlayers(player, alivePlayerIds, 1, 1,
      "#sk__yinyuan-choose", sk__yinyuan.name, true)
    if #to > 0 then
      event:setCostData(self, to[1])
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local to = room:getPlayerById(event:getCostData(self))
    local cards = table.filter(room.draw_pile, function(id)
      return Fk:getCardById(id).suit == Card.Heart
    end)
    if #cards == 0 then return end
    room:moveCardTo(table.random(cards), Card.PlayerHand, to, fk.ReasonJustMove, sk__yinyuan.name, nil, true, player)
    if player.dead then return end
    local mark = player:getTableMark(sk__yinyuan.name)
    if table.insertIfNeed(mark, to.id) then
      room:setPlayerMark(player, sk__yinyuan.name, mark)
      cards = table.filter(room.draw_pile, function(id)
        return Fk:getCardById(id).suit == Card.Heart
      end)
      if #cards == 0 then return end
      room:moveCardTo(table.random(cards), Card.PlayerHand, player, fk.ReasonJustMove, sk__yinyuan.name, nil, true, player)
    end
  end,
})

return sk__yinyuan